<?php  
class Productmodel extends Model {
var $id = 0;
var $firmid = 0;
var $name = "";
var $description = "";
var $producttype = 0;
var $created = "";
var $price = 0;
var $isactive = true;

function Productmodel()
    {
        // Call the Model constructor
        parent::Model(); 
    }

function get($id)
	{
		if(!is_numeric($id)) return false;
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('id',$id);
		$query = $this->db->get();
		return $query;
	}	
}

function get_all_short()
{
		$this->db->select('id,name');
		$this->db->from('products');
		$query = $this->db->get();
		return $query;
}

function update($record)
{
	if(is_array($record))
	{
		foreach($record as $k=>$v)
		{
			if(isset($this->{$k})) $this->{$k} = $v;
		}
	}
}

function save()
{
	$data_to_save = array(
	"firmid"=>$this->firmid,
	"name"=>$this->name,
	"description"=>$this->description,
	"producttype"=>$this->producttype,
	"price"=>$this->price,
	"isactive"=>$this->isactive
	)
	if($this->id>0)
	{
		$this->db->where("id",$this->id);
		$this->db->update($data_to_save);
	}
	else
	{
		$data_to_save["created"] = date();
		$this->db->insert("products",$data_to_save);
	}
}

?>